
	use "$dir/rawdata/LSMS Malawi/2010/Full_Sample/Household/hh_mod_b.dta", clear // household roster
	compress
	
	/*
		5 MODULE B: HOUSEHOLD ROSTER 
		8 MODULE C: EDUCATION
		11 MODULE D: HEALTH
		16 MODULE E: TIME USE & LABOUR 
		32 MODULE F: HOUSING
		35 MODULE F_1: LAND ROSTER
		47 MODULE H: FOOD SECURITY
		48 MODULE I: NON-FOOD EXPENDITURES – OVER PAST ONE WEEK & ONE MONTH
		49 MODULE J: NON-FOOD EXPENDITURES
		50 MODULE K: NON-FOOD EXPENDITURES OVER PAST 12 MONTHS
		51 MODULE L: DURABLE GOODS
		53 MODULE M: FARM IMPLEMENTS, MACHINERY, AND STRUCTURES
		55 MODULE N: HOUSEHOLD ENTERPRISES
		63 MODULE O: CHILDREN LIVING ELSEWHERE
		65 MODULE P: OTHER INCOME
		67 MODULE Q: GIFTS GIVEN OUT
		68 MODULE R: SOCIAL SAFETY NETS
		70 MODULE S: CREDIT
		72 MODULE T: SUBJECTIVE ASSESSMENT OF WELL-BEING 
		74 MODULE U: SHOCKS & COPING STRATEGIES
		75 MODULE V: CHILD ANTHROPOMETRY
		76 MODULE W: DEATHS
		77 MODULE X: FILTER QUESTIONS FOR AGRICULTURE &
		FISHERY QUESTIONNAIRES
	*/
	
	merge m:1 case_id using "$dir/rawdata/LSMS Malawi/2010/Full_Sample/ihs3fc2M_consumption.dta", assert(matched) nogen	// consumption aggregate
	merge 1:1 case_id id_code using "$dir/rawdata/LSMS Malawi/2010/Full_Sample/Household/hh_mod_d.dta", keep(master matched) nogen // health
	merge 1:1 case_id id_code using "$dir/rawdata/LSMS Malawi/2010/Full_Sample/Household/hh_mod_e.dta", keep(master matched) nogen // time use and labor
	merge m:1 case_id using "$dir/rawdata/LSMS Malawi/2010/Full_Sample/Household/hh_mod_t.dta", keep(master matched) nogen // subjective well-being
	merge m:1 case_id using "$dir/rawdata/LSMS Malawi/2010/Full_Sample/Household/hh_mod_a_filt.dta", keep(master matched) nogen // for urban status
	
	ren case_id hhid
	ren id_code indiv
	
		** INFORMATION FROM HOUSEHOLD ROSTER

		** Still in HH
			gen w3_inhh=1 // FIXME: No specific question asking this
		
		** Age
			gen w3_age=hh_b05a
			
		** Household size
			gen temp=1 if w3_inhh==1
			bys hhid: egen w3_hh_size=total(temp)
			drop temp

		** Number of children 12 or younger
			gen temp=1 if w3_age<=12 & w3_inhh==1
			bys hhid: egen w3_hh_under12=total(temp)
			drop temp

		** Number of youth 18 or younger
			gen temp=1 if w3_age<=18 & w3_inhh==1
			bys hhid: egen w3_hh_under18=total(temp)
			drop temp

		** Number of adults 60 or older
			gen temp=1 if w3_age>=60 & !missing(w3_age) & w3_age!=999 & w3_inhh==1
			bys hhid: egen w3_hh_over60=total(temp)
			drop temp

		** Adults 12 to 60
			gen temp=1 if w3_age>12 & w3_age<60 & !missing(w3_age) & w3_age!=999 & w3_inhh==1
			bys hhid: egen w3_hh_12to60=total(temp)
			drop temp

		** Marital status
			gen w3_married=(hh_b24==1 | hh_b24==2) if !missing(hh_b24)
			gen w3_married_monog=(hh_b24==1) if !missing(hh_b24)
			gen w3_married_polyg=(hh_b24==2) if !missing(hh_b24)

		** Female
			gen w3_female=(hh_b03==2) if !missing(hh_b03)

		** Age of spouse
			sum indiv
			forvalues x=1/`r(max)' {
				gen age_person`x'_temp=w3_age if indiv==`x' & !missing(w3_age)
				bys hhid: egen age_person`x'=max(age_person`x'_temp)
				drop age_person`x'_temp
			}

		** Average age of others in the household
			sum indiv 
			forvalues x=1/`r(max)' {
				replace age_person`x'=. if indiv==`x'
			}
			egen w3_hh_avgage=rowmean(age_person*)
			
		** Spouse age
			sum indiv
			forvalues x=1/`r(max)' {
				replace age_person`x'=. if hh_b26a!=`x' // FIXME: Only for the first wife
			}
			egen w3_spouse_age=rowmean(age_person*)

		** Age gap
			gen w3_spouse_agegap=w3_age-w3_spouse_age

		** Birth year
			gen w3_birthyear=hh_b06b
			recode w3_birthyear 9999=. 9998=.
			replace w3_birthyear=2010-w3_age if missing(w3_birthyear)
			
	***********
	***********
	
	** Geographic information
	
		gen w3_urban=(reside==1) if !missing(reside)
		
	** Consumption
	
		gen w3_conspc=expagg/w3_hh_size
			*sum rexpaggpc, de
			*scatter w3_conspc rexpaggpc if rexpaggpc<`r(p99)' // to check

	***********
	***********

	** LABOR

		** Worked for a non-HH member
			gen w3_work_outsideHH1=hh_e10>0 if !missing(hh_e10) // casual part-time
			gen w3_work_outsideHH2=hh_e11>0 if !missing(hh_e11) // wage or salary labor
		
			egen w3_work_outsideHH=rowmax(w3_work_outsideHH1 w3_work_outsideHH2)
			
			gen w3_work_outsideHH1_hrs=hh_e10 if !missing(hh_e10) // casual part-time
			gen w3_work_outsideHH2_hrs=hh_e11 if !missing(hh_e11) // wage or salary labor
			
			egen w3_work_outsideHH_hrs=rowtotal(w3_work_outsideHH1_hrs w3_work_outsideHH2_hrs), mi 
			replace w3_work_outsideHH_hrs=0 if w3_work_outsideHH==0
			
		** Worked in agriculture for a HH member
			gen w3_work_agHH=hh_e07>0 if !missing(hh_e07)
			gen w3_work_agHH_hrs=hh_e07 if !missing(hh_e07)	
			replace w3_work_agHH_hrs=0 if w3_work_agHH==0
			
		** Worked in HH business
			gen w3_work_bizHH1=hh_e08>0 if !missing(hh_e08) // run biz
			gen w3_work_bizHH2=hh_e09>0 if !missing(hh_e09) // help in biz
			
			egen w3_work_bizHH=rowmax(w3_work_bizHH1 w3_work_bizHH2)
			
			gen w3_work_bizHH1_hrs=hh_e08 if !missing(hh_e08) // run biz
			gen w3_work_bizHH2_hrs=hh_e09 if !missing(hh_e09) // help in biz
					
			egen w3_work_bizHH_hrs=rowtotal(w3_work_bizHH1_hrs w3_work_bizHH1_hrs), mi
			replace w3_work_bizHH_hrs=0 if w3_work_bizHH==0
			
		** Any work in last 7 days (agriculture, for non-HH member, own account/business)
			egen w3_worked_last7days=rowmax(w3_work_outsideHH w3_work_agHH w3_work_bizHH)
			
		** Hours worked in last 7 days
			egen w3_work_hrs=rowtotal(w3_work_outsideHH_hrs w3_work_agHH_hrs w3_work_bizHH_hrs)
			replace w3_work_hrs=. if missing(w3_work_outsideHH_hrs) & missing(w3_work_agHH_hrs) & missing(w3_work_bizHH_hrs)
				
		** Works in agriculture
			gen w3_work_agri=(w3_work_agHH==1) if !missing(w3_work_agHH)
		
	***********
	***********

	** HEALTH
	
		** Any illness or injury during the last 2 weeks
			gen w3_ill_inj=(hh_d04==1) if !missing(hh_d04)

		** Had to stop usual activity in the past 4 weeks
			gen w3_ill_inj_stopactivity=(hh_d08>0) if !missing(hh_d08)
			replace w3_ill_inj_stopactivity=0 if w3_ill_inj==0
			
	***********
	***********
	
	** SUBJECTIVE WELL-BEING
	
		** Access to health care
			gen w3_healthcare_inadequate=hh_t04==1 if !missing(hh_t04)
			
		** Food consumption
			gen w3_foodcons_inadequate=hh_t01==1 if !missing(hh_t01)

	***********
	***********
	
	** DISABILITIES

	** Difficulty seeing
		tab1 hh_d24, nol
		tab1 hh_d24
		gen w3_diff_seei=1 if inlist(hh_d24, 2, 3, 4) 
		replace w3_diff_seei=0 if inlist(hh_d24, 1)
		replace w3_diff_seei=. if inlist(hh_d24, .)
		tab1 w3_diff_seei

	** Difficulty hearing
		tab1 hh_d25, nol
		tab1 hh_d25
		gen w3_diff_hear=1 if inlist(hh_d25, 2, 3, 4) 
		replace w3_diff_hear=0 if inlist(hh_d25, 1)
		replace w3_diff_hear=. if inlist(hh_d25, .)
		tab1 w3_diff_hear

	** Difficulty walking or climbing stairs	
		tab1 hh_d26, nol
		tab1 hh_d26
		gen w3_diff_walk_clim=1 if inlist(hh_d26, 2, 3, 4) 
		replace w3_diff_walk_clim=0 if inlist(hh_d26, 1)
		replace w3_diff_walk_clim=. if inlist(hh_d26, .)
		tab1 w3_diff_walk_clim

	** Difficulty remembering or concentrating
		tab1 hh_d27, nol
		tab1 hh_d27
		gen w3_diff_reme=1 if inlist(hh_d27, 2, 3, 4) 
		replace w3_diff_reme=0 if inlist(hh_d27,1)
		replace w3_diff_reme=. if inlist(hh_d27, .)
		tab1 w3_diff_reme

	** Difficulty with self-care
		tab1 hh_d28, nol
		tab1 hh_d28
		gen w3_diff_self_care=1 if inlist(hh_d28, 2, 3, 4)
		replace w3_diff_self_care=0 if inlist(hh_d28, 1)
		replace w3_diff_self_care=. if inlist(hh_d28, .)
		tab1 w3_diff_self_care

	** Difficulty communicating
		tab1 hh_d29, nol
		tab1 hh_d29
		gen w3_diff_comm=1 if inlist(hh_d29, 2, 3, 4) 
		replace w3_diff_comm=0 if inlist(hh_d29, 1)
		replace w3_diff_comm=. if inlist(hh_d29, .)
		tab1 w3_diff_comm

	***********
	***********
	
	** SAVE
	
		keep hhid indiv w3*
		order hhid indiv w3*
		save "$dir/data/MLW_w3_individual.dta", replace
